import pygame
import sys
import time
from test53class_morse2 import Morse


def play_morse(str):
    WIN_X = 150
    WIN_Y = 60

    BLACK = 0, 0, 0
    WHITE = 255, 255, 255
    GOLD = 255, 251, 0
    RED = pygame.Color('red')
    GREEN = 0, 255, 0
    BLUE = 0, 0, 255
    YELLOW = pygame.Color('yellow')
    fps = 300
    fclock = pygame.time.Clock()

    title_name = 'new pygame'
    init_result = pygame.init()

    # Create a window
    screen = pygame.display.set_mode((WIN_X, WIN_Y))
    # Set title
    pygame.display.set_caption(title_name)

    dash_file = 'mp3\\dash.mp3'
    dot_file = 'mp3\\dot.mp3'
    sleeptime = 0.6
    for s in str:
        if s == '-':
            pygame.mixer.music.load(dash_file)
            pygame.mixer.music.play()
            time.sleep(sleeptime)
        elif s == '.':
            pygame.mixer.music.load(dot_file)
            pygame.mixer.music.play()
            time.sleep(sleeptime)
        else:
            time.sleep(sleeptime)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('BYE-BYE')
                pygame.quit()
                sys.exit()

        fclock.tick(fps)
    # # audio_file = 'audios\wrong.m4a'
if __name__ == '__main__':
    word = 'ae'
    str = Morse().word_to_morse(word)
    print(str)
    play_morse(str)
